﻿using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using TSharp.Core.Aop.Handler;

namespace TSharp.Core.Aop.Attribute
{
    /// <summary>
    /// 验证方法中参数比某个数字大的定制特性
    /// </summary>
    public class MoreThanAttribute : HandlerAttribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MoreThanAttribute"/> class.
        /// </summary>
        /// <param name="parameterName">Name of the parameter.</param>
        /// <param name="moreThanNumber">The more than number.</param>
        public MoreThanAttribute(string parameterName, int moreThanNumber)
        {
            ParameterName = parameterName;
            MoreThanNumber = moreThanNumber;
        }

        /// <summary>
        /// 参数名
        /// </summary>
        public string ParameterName { get; set; }

        /// <summary>
        /// 必须大于的数字
        /// </summary>
        public int MoreThanNumber { get; set; }

        /// <summary>
        /// Derived classes implement this method. When called, it
        /// creates a new call handler as specified in the attribute
        /// configuration.
        /// </summary>
        /// <param name="container">The <see cref="T:Microsoft.Practices.Unity.IUnityContainer"/> to use when creating handlers,
        /// if necessary.</param>
        /// <returns>A new call handler object.</returns>
        public override ICallHandler CreateHandler(IUnityContainer container)
        {
            return new MoreThanHandler(ParameterName, MoreThanNumber, Order);
        }
    }
}